package Tydzien3;
import java.util.Arrays;
import java.util.Comparator;


public class Tydzien3{
	private Ksiazka[] biblioteka = new Ksiazka[10];
	private int n = 0;
	
	public void appendElement(Ksiazka k)
	{
		if(n == biblioteka.length)
		{
			biblioteka = Arrays.copyOf(biblioteka, n + 10);
		}
		biblioteka[n++] = k;
	}
	
	public void removeElement(int i)
	{
		if(i >= 0 && i < n)
		{
			System.arraycopy(biblioteka, i+1, biblioteka, i, n-1-i);
			n--;
		}
		else
		{
			throw new ArrayIndexOutOfBoundsException();
		}
	}
	
	public Ksiazka getElement(int i)
	{
		if(i >= 0 && i < n)
		{
			return biblioteka[i];
		}
		else
		{
			throw new ArrayIndexOutOfBoundsException();
		}		
	}
	
	public void sort()
	{
		Ksiazka[] temp = Arrays.copyOf(biblioteka, n);
		Arrays.sort(temp);
		System.arraycopy(temp, 0, biblioteka, 0, n);
	}
	
	public void sort(Comparator<Ksiazka> c)
	{
		Ksiazka[] temp = Arrays.copyOf(biblioteka, n);
		Arrays.sort(temp, c);
		System.arraycopy(temp, 0, biblioteka, 0, n);
	}
	
	public int size()
	{
		return n;
	}
	
	public String toString()
	{
		String s = new String();
		for(int i = 0; i < n; ++i)
		{
			s = s.concat(biblioteka[i].toString()).concat("\n");
		}
		return s;
	}
	
	@Override
	public boolean equals(Object obj) {
		if(obj instanceof Tydzien3)
		{
			Tydzien3 b = (Tydzien3) obj;
			for(int i = 0; i < n; ++i)
			{
				if(!biblioteka[i].equals(b.biblioteka[i]))
				{
					return false;
				}
			}
			return true;
		}
		else
		{
			return super.equals(obj);
		}
	}

}
